Skip to content

Instantly share code, notes, and snippets.

@ayamflow
Created January 29, 2018 20:21
Show Gist options
  • Save ayamflow/944230a1fcffeb5b8850b96867f3257e to your computer and use it in GitHub Desktop.
Save ayamflow/944230a1fcffeb5b8850b96867f3257e to your computer and use it in GitHub Desktop.
Trim decimals for 3D JSON models
var fs = require('fs');
var argv = require('minimist')(process.argv.slice(2));
let data = JSON.parse(fs.readFileSync('./' + argv.input, 'utf8'));
Object.keys(data).forEach(function(key) {
if (data[key] instanceof Array) {
data[key].forEach(function(value, i) {
data[key][i] = parseFloat(parseFloat(value).toFixed(3 || argv.cs));
});
}
});
fs.writeFileSync('./' + argv.output, JSON.stringify(data), 'utf8');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment