Skip to content

Commit 672258e

Browse files
committed
Add .toJSON to BufferAttribute
1 parent 976f1b6 commit 672258e

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

src/core/BufferAttribute.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,16 @@ Object.assign( BufferAttribute.prototype, {
319319

320320
return new this.constructor( this.array, this.itemSize ).copy( this );
321321

322+
},
323+
324+
toJSON: function() {
325+
326+
return {
327+
itemSize: this.itemSize,
328+
type: this.array.constructor.name,
329+
array: Array.prototype.slice.call( this.array ),
330+
normalized: this.normalized
331+
};
322332
}
323333

324334
} );

src/core/BufferGeometry.js

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,12 +1063,7 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
10631063

10641064
var attribute = attributes[ key ];
10651065

1066-
var attributeData = {
1067-
itemSize: attribute.itemSize,
1068-
type: attribute.array.constructor.name,
1069-
array: Array.prototype.slice.call( attribute.array ),
1070-
normalized: attribute.normalized
1071-
};
1066+
var attributeData = attribute.toJSON();
10721067

10731068
if ( attribute.name !== '' ) attributeData.name = attribute.name;
10741069

@@ -1089,12 +1084,7 @@ BufferGeometry.prototype = Object.assign( Object.create( EventDispatcher.prototy
10891084

10901085
var attribute = attributeArray[ i ];
10911086

1092-
var attributeData = {
1093-
itemSize: attribute.itemSize,
1094-
type: attribute.array.constructor.name,
1095-
array: Array.prototype.slice.call( attribute.array ),
1096-
normalized: attribute.normalized
1097-
};
1087+
var attributeData = attribute.toJSON();
10981088

10991089
if ( attribute.name !== '' ) attributeData.name = attribute.name;
11001090

src/core/InstancedBufferAttribute.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,18 @@ InstancedBufferAttribute.prototype = Object.assign( Object.create( BufferAttribu
3636

3737
return this;
3838

39+
},
40+
41+
toJSON: function () {
42+
43+
var data = BufferAttribute.prototype.toJSON.call( this );
44+
45+
data.meshPerAttribute = this.meshPerAttribute;
46+
47+
data.isInstancedBufferAttribute = true;
48+
49+
return data;
50+
3951
}
4052

4153
} );

0 commit comments

Comments
 (0)