提交 2c45f3ed 编写于 作者: M Mr.doob

Material: Fixed toJSON() as root. See #7337

上级 8f9ab7a3
......@@ -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;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册