From 257b59650d20b03dbb5902aa4598eac3b9233382 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 21 Oct 2015 20:13:16 +0200 Subject: [PATCH] CmdSetMaterial: Simplified .toJSON() --- editor/js/CmdSetMaterial.js | 52 +++---------------------------------- 1 file changed, 4 insertions(+), 48 deletions(-) diff --git a/editor/js/CmdSetMaterial.js b/editor/js/CmdSetMaterial.js index 40246fdbd0..d5d8712288 100755 --- a/editor/js/CmdSetMaterial.js +++ b/editor/js/CmdSetMaterial.js @@ -43,55 +43,11 @@ CmdSetMaterial.prototype = { var output = Cmd.prototype.toJSON.call( this ); output.objectUuid = this.object.uuid; - output.oldMaterial = serializeMaterial( this.oldMaterial ); - output.newMaterial = serializeMaterial( this.newMaterial ); + output.oldMaterial = this.oldMaterial.toJSON(); + output.newMaterial = this.newMaterial.toJSON(); return output; - - function serializeMaterial ( material ) { - - if ( material === undefined ) return null; - - var meta = { - geometries: {}, - materials: {}, - textures: {}, - images: {} - }; - - var json = {}; - json.materials = [ material.toJSON( meta ) ]; - - var textures = extractFromCache( meta.textures ); - var images = extractFromCache( meta.images ); - - if ( textures.length > 0 ) json.textures = textures; - if ( images.length > 0 ) json.images = images; - - return json; - - } - - // Note: The function 'extractFromCache' is copied from Object3D.toJSON() - - // extract data from the cache hash - // remove metadata on each item - // and return as array - function extractFromCache ( cache ) { - - var values = []; - for ( var key in cache ) { - - var data = cache[ key ]; - delete data.metadata; - values.push( data ); - - } - return values; - - } - }, fromJSON: function ( json ) { @@ -108,8 +64,8 @@ CmdSetMaterial.prototype = { var loader = new THREE.ObjectLoader(); var images = loader.parseImages( json.images ); var textures = loader.parseTextures( json.textures, images ); - var materials = loader.parseMaterials( json.materials, textures ); - return materials[ json.materials[ 0 ].uuid ]; + var materials = loader.parseMaterials( [ json ], textures ); + return materials[ json.uuid ]; } -- GitLab