|
@@ -115,6 +115,17 @@ THREE.Material.prototype = {
|
|
|
|
|
|
toJSON: function ( meta ) {
|
|
|
|
|
|
+ var isRoot = meta === undefined;
|
|
|
+
|
|
|
+ if ( isRoot ) {
|
|
|
+
|
|
|
+ meta = {
|
|
|
+ textures: {},
|
|
|
+ images: {}
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
var data = {
|
|
|
metadata: {
|
|
|
version: 4.4,
|
|
@@ -176,6 +187,28 @@ THREE.Material.prototype = {
|
|
|
if ( this.alphaTest > 0 ) data.alphaTest = this.alphaTest;
|
|
|
if ( this.wireframe === true ) data.wireframe = this.wireframe;
|
|
|
if ( this.wireframeLinewidth > 1 ) data.wireframeLinewidth = this.wireframeLinewidth;
|
|
|
+
|
|
|
+ // TODO: Copied from Object3D.toJSON
|
|
|
+
|
|
|
+ function extractFromCache ( cache ) {
|
|
|
+ var values = [];
|
|
|
+ for ( var key in cache ) {
|
|
|
+ var data = cache[ key ];
|
|
|
+ delete data.metadata;
|
|
|
+ values.push( data );
|
|
|
+ }
|
|
|
+ return values;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( isRoot ) {
|
|
|
+
|
|
|
+ var textures = extractFromCache( meta.textures );
|
|
|
+ var images = extractFromCache( meta.images );
|
|
|
+
|
|
|
+ if ( textures.length > 0 ) data.textures = textures;
|
|
|
+ if ( images.length > 0 ) data.images = images;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
return data;
|
|
|
|