@@ -874,22 +874,27 @@ THREE.BufferGeometry.prototype = {
874874 }
875875 } ,
876876
877- toJSON : function ( ) {
878-
879- var output = {
880- metadata : {
881- version : 4.0 ,
882- type : 'BufferGeometry' ,
883- generator : 'BufferGeometryExporter'
884- } ,
885- uuid : this . uuid ,
886- type : this . type ,
887- data : {
888- attributes : { }
889- }
890- } ;
877+ toJSON : function ( ) {
891878
892- var attributes = this . attributes ;
879+ // we will store all serialization data on 'data'
880+ var data = { } ;
881+
882+ // add metadata
883+ data . metadata = {
884+ version : 4.4 ,
885+ type : 'BufferGeometry' ,
886+ generator : 'BufferGeometry.toJSON'
887+ }
888+
889+ // standard BufferGeometry serialization
890+
891+ data . type = this . type ;
892+ data . uuid = this . uuid ;
893+ if ( this . name !== '' ) data . name = this . name ;
894+ data . data = { } ;
895+ data . data . attributes = { } ;
896+
897+ var attributes = this . attributes ;
893898 var offsets = this . offsets ;
894899 var boundingSphere = this . boundingSphere ;
895900
@@ -899,7 +904,7 @@ THREE.BufferGeometry.prototype = {
899904
900905 var array = Array . prototype . slice . call ( attribute . array ) ;
901906
902- output . data . attributes [ key ] = {
907+ data . data . attributes [ key ] = {
903908 itemSize : attribute . itemSize ,
904909 type : attribute . array . constructor . name ,
905910 array : array
@@ -909,20 +914,20 @@ THREE.BufferGeometry.prototype = {
909914
910915 if ( offsets . length > 0 ) {
911916
912- output . data . offsets = JSON . parse ( JSON . stringify ( offsets ) ) ;
917+ data . data . offsets = JSON . parse ( JSON . stringify ( offsets ) ) ;
913918
914919 }
915920
916921 if ( boundingSphere !== null ) {
917922
918- output . data . boundingSphere = {
923+ data . data . boundingSphere = {
919924 center : boundingSphere . center . toArray ( ) ,
920925 radius : boundingSphere . radius
921926 }
922927
923928 }
924929
925- return output ;
930+ return data ;
926931
927932 } ,
928933
0 commit comments