Skip to content

Instantly share code, notes, and snippets.

@AndrewRayCode
Created April 23, 2016 04:27
Show Gist options
  • Save AndrewRayCode/15340499495afea654e45d9ace113d28 to your computer and use it in GitHub Desktop.
Save AndrewRayCode/15340499495afea654e45d9ace113d28 to your computer and use it in GitHub Desktop.
var fs = require('fs');
var path = require('path');
var filename = path.resolve( __dirname, process.argv[ 2 ] );
var contents = require( filename );
// First delete the useless animations key that crashes the object loader
// https://github.com/mrdoob/three.js/issues/8723
delete contents.animations;
contents.geometries = contents.geometries.map(function( geometry ) {
var morphTargets = geometry.data.morphTargets;
// Fix morphTargets, which are exported as [ [x,y,z], [x,y,z]... ] but
// should be [ x,y,z,x,y,z... ]
// see https://github.com/mrdoob/three.js/issues/7724
if( morphTargets && morphTargets.length ) {
geometry.data.morphTargets = morphTargets.map(function( data ) {
var vertices = [].concat.apply( [], data.vertices );
return {
name: data.name,
vertices: vertices
};
});
}
return geometry;
});
fs.writeFile( filename, JSON.stringify( contents, null, 2 ) );
@AndrewRayCode
Copy link
Author

AndrewRayCode commented Apr 23, 2016

Usage:

node fix-blender-export.js relative/path/to/your/file.json

Warning this will overwrite the original file you pass in!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment