miijs 2.2.1 → 2.2.2
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 +106 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2288,9 +2288,13 @@ function convertMiiToStudio(jsonIn) {
|
|
|
2288
2288
|
}
|
|
2289
2289
|
async function readWiiBin(binOrPath) {
|
|
2290
2290
|
let data;
|
|
2291
|
-
if
|
|
2291
|
+
if(Buffer.isBuffer(binOrPath)){
|
|
2292
|
+
data=binOrPath;
|
|
2293
|
+
}
|
|
2294
|
+
else if (/[^01]/ig.test(binOrPath)) {
|
|
2292
2295
|
data = await fs.promises.readFile(binOrPath);
|
|
2293
|
-
}
|
|
2296
|
+
}
|
|
2297
|
+
else{
|
|
2294
2298
|
data = Buffer.from(binOrPath);
|
|
2295
2299
|
}
|
|
2296
2300
|
var thisMii={
|
|
@@ -3257,6 +3261,100 @@ function generateInstructions(mii,full){
|
|
|
3257
3261
|
}
|
|
3258
3262
|
}
|
|
3259
3263
|
|
|
3264
|
+
function miiHeightToFeetInches(value) {
|
|
3265
|
+
const minInches = 36; // 3'0"
|
|
3266
|
+
const midInches = 69; // 5'9"
|
|
3267
|
+
const maxInches = 84; // 7'0"
|
|
3268
|
+
const midPoint = 64;
|
|
3269
|
+
|
|
3270
|
+
let totalInches;
|
|
3271
|
+
if (value <= midPoint) {
|
|
3272
|
+
// Lower half: 0–64 maps to 36–69
|
|
3273
|
+
totalInches = minInches + (value / midPoint) * (midInches - minInches);
|
|
3274
|
+
}
|
|
3275
|
+
else {
|
|
3276
|
+
// Upper half: 64–127 maps to 69–84
|
|
3277
|
+
totalInches = midInches + ((value - midPoint) / (127 - midPoint)) * (maxInches - midInches);
|
|
3278
|
+
}
|
|
3279
|
+
|
|
3280
|
+
const feet = Math.floor(totalInches / 12);
|
|
3281
|
+
const inches = Math.round(totalInches % 12);
|
|
3282
|
+
return { feet, inches, totalInches };
|
|
3283
|
+
}
|
|
3284
|
+
function inchesToMiiHeight(totalInches) {
|
|
3285
|
+
const minInches = 36;
|
|
3286
|
+
const midInches = 69;
|
|
3287
|
+
const maxInches = 84;
|
|
3288
|
+
const midPoint = 64;
|
|
3289
|
+
|
|
3290
|
+
let value;
|
|
3291
|
+
if (totalInches <= midInches) {
|
|
3292
|
+
// Below or equal to midpoint
|
|
3293
|
+
value = ((totalInches - minInches) / (midInches - minInches)) * midPoint;
|
|
3294
|
+
} else {
|
|
3295
|
+
// Above midpoint
|
|
3296
|
+
value = midPoint + ((totalInches - midInches) / (maxInches - midInches)) * (127 - midPoint);
|
|
3297
|
+
}
|
|
3298
|
+
|
|
3299
|
+
return Math.round(Math.max(0, Math.min(value, 127)));
|
|
3300
|
+
}
|
|
3301
|
+
// ---- Tunable anchors (BMI breakpoints) ----
|
|
3302
|
+
const BMI_MIN = 16; // maps to Mii weight 0
|
|
3303
|
+
const BMI_MID = 23; // maps to Mii weight 64 (average look)
|
|
3304
|
+
const BMI_MAX = 40; // maps to Mii weight 127
|
|
3305
|
+
|
|
3306
|
+
// Convenience: clamp helper
|
|
3307
|
+
const clamp = (x, lo, hi) => Math.max(lo, Math.min(hi, x));
|
|
3308
|
+
|
|
3309
|
+
/**
|
|
3310
|
+
* Convert real-world height & weight to Mii weight (0–127) using BMI.
|
|
3311
|
+
* @param {number} heightInches - Total height in inches
|
|
3312
|
+
* @param {number} weightLbs - Weight in pounds
|
|
3313
|
+
* @returns {number} - Mii weight index (0–127)
|
|
3314
|
+
*/
|
|
3315
|
+
function heightWeightToMiiWeight(heightInches, weightLbs) {
|
|
3316
|
+
if (!heightInches || heightInches <= 0) throw new Error("heightInches must be > 0");
|
|
3317
|
+
const bmi = (703 * weightLbs) / (heightInches * heightInches);
|
|
3318
|
+
|
|
3319
|
+
let v;
|
|
3320
|
+
if (bmi <= BMI_MID) {
|
|
3321
|
+
// Map BMI_MIN..BMI_MID -> 0..64
|
|
3322
|
+
const t = (clamp(bmi, BMI_MIN, BMI_MID) - BMI_MIN) / (BMI_MID - BMI_MIN);
|
|
3323
|
+
v = 0 + t * 64;
|
|
3324
|
+
} else {
|
|
3325
|
+
// Map BMI_MID..BMI_MAX -> 64..127
|
|
3326
|
+
const t = (clamp(bmi, BMI_MID, BMI_MAX) - BMI_MID) / (BMI_MAX - BMI_MID);
|
|
3327
|
+
v = 64 + t * (127 - 64);
|
|
3328
|
+
}
|
|
3329
|
+
return Math.round(clamp(v, 0, 127));
|
|
3330
|
+
}
|
|
3331
|
+
|
|
3332
|
+
/**
|
|
3333
|
+
* Convert Mii weight (0–127) back to a realistic real-world weight (lbs)
|
|
3334
|
+
* for a given height, by inverting the BMI mapping above.
|
|
3335
|
+
* @param {number} heightInches - Total height in inches
|
|
3336
|
+
* @param {number} miiWeight - 0..127
|
|
3337
|
+
* @returns {{ pounds:number, bmi:number }}
|
|
3338
|
+
*/
|
|
3339
|
+
function miiWeightToRealWeight(heightInches, miiWeight) {
|
|
3340
|
+
if (!heightInches || heightInches <= 0) heightInches=0;
|
|
3341
|
+
const v = clamp(miiWeight, 0, 127);
|
|
3342
|
+
|
|
3343
|
+
let bmi;
|
|
3344
|
+
if (v <= 64) {
|
|
3345
|
+
// Invert 0..64 -> BMI_MIN..BMI_MID
|
|
3346
|
+
const t = v / 64;
|
|
3347
|
+
bmi = BMI_MIN + t * (BMI_MID - BMI_MIN);
|
|
3348
|
+
} else {
|
|
3349
|
+
// Invert 64..127 -> BMI_MID..BMI_MAX
|
|
3350
|
+
const t = (v - 64) / (127 - 64);
|
|
3351
|
+
bmi = BMI_MID + t * (BMI_MAX - BMI_MID);
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3354
|
+
const pounds = (bmi * heightInches * heightInches) / 703;
|
|
3355
|
+
return { pounds, bmi };
|
|
3356
|
+
}
|
|
3357
|
+
|
|
3260
3358
|
|
|
3261
3359
|
|
|
3262
3360
|
module.exports = {
|
|
@@ -3278,5 +3376,10 @@ module.exports = {
|
|
|
3278
3376
|
|
|
3279
3377
|
//make3DSChild, //WIP
|
|
3280
3378
|
|
|
3281
|
-
generateInstructions
|
|
3379
|
+
generateInstructions,
|
|
3380
|
+
|
|
3381
|
+
miiHeightToFeetInches,
|
|
3382
|
+
inchesToMiiHeight,
|
|
3383
|
+
heightWeightToMiiWeight,
|
|
3384
|
+
miiWeightToRealWeight
|
|
3282
3385
|
}
|