javascript - Three.js BufferGeometry.toJSON - Why are the Attribute data not exported? -


i trying export buffer geometry json file.

here code using:

var output = object.geometry.tojson();  try  {     output = json.stringify( output, null, '\t' );     output = output.replace( /[\n\t]+([\d\.e\-\[\]]+)/g, '$1' ); }  catch ( e )  {     output = json.stringify( output ); }  alert ("done json "); 

this produces json text object such this:

{     "metadata": {         "version": 4.4,         "type": "buffergeometry",         "generator": "buffergeometry.tojson"     },     "uuid": "f871289f-c8ff-4760-a6ea-c9e5fd956702",     "type": "planebuffergeometry",     "width": 7500,     "height": 7500,     "widthsegments": 15,     "heightsegments": 15 } 

however geometry contains various arrays of attribute data (positions, normals, colors, uvs) not included in json text.

i have located relevant code in current build of three.js (r79) (line 12295 onwards):

tojson: function () {  var data = {     metadata: {         version: 4.4,         type: 'buffergeometry',         generator: 'buffergeometry.tojson'     } };  // standard buffergeometry serialization  data.uuid = this.uuid; data.type = this.type; if ( this.name !== '' ) data.name = this.name;  if ( this.parameters !== undefined ) {      var parameters = this.parameters;      ( var key in parameters ) {          if ( parameters[ key ] !== undefined ) data[ key ] = parameters[ key ];      }      return data; // *** no attributes have been considered yet!  }  data.data = { attributes: {} };   // *** attributes not defined yet! 

it appears code logic (and confirmed debugging) "data" object returned .tojson function before attributes considered.

so bug or missing here?

update

u1: suggested /u/radio/ tried converting buffergeometry normal three.geometry , running .tojson() on that. worked, vertex data included in json file.

u2: in particular planebuffergeometry have modified vertex positions after creation. 3 code (above) looks .parameters property of geometry , if finds 1 returns data , exits .tojson function without carrying on include various attributes in output json file. seems strange thing do.

u3: tried deleting .parameters property buffergeometry. after buffergeometry.tojson() function produce output includes expected/desired various attribute array data. not seem compromize further working of sculpter (but not sure safe hack).


Comments