Bladeren bron

Scene: Serialise background.

Mr.doob 9 jaren geleden
bovenliggende
commit
0f29aab349
3 gewijzigde bestanden met toevoegingen van 17 en 0 verwijderingen
  1. 10 0
      src/loaders/ObjectLoader.js
  2. 6 0
      src/math/Color.js
  3. 1 0
      src/scenes/Scene.js

+ 10 - 0
src/loaders/ObjectLoader.js

@@ -489,6 +489,16 @@ Object.assign( ObjectLoader.prototype, {
 
 					object = new Scene();
 
+					if ( data.background !== undefined ) {
+
+						if ( Number.isInteger( data.background ) ) {
+
+							object.background = new THREE.Color( data.background );
+
+						}
+
+					}
+
 					if ( data.fog !== undefined ) {
 
 						if ( data.fog.type === 'Fog' ) {

+ 6 - 0
src/math/Color.js

@@ -486,6 +486,12 @@ Color.prototype = {
 
 		return array;
 
+	},
+
+	toJSON: function () {
+
+		return this.getHex();
+
 	}
 
 };

+ 1 - 0
src/scenes/Scene.js

@@ -41,6 +41,7 @@ Scene.prototype.toJSON = function ( meta ) {
 
 	var data = Object3D.prototype.toJSON.call( this, meta );
 
+	if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
 	if ( this.fog !== null ) data.object.fog = this.fog.toJSON();
 
 	return data;