Browse Source

Merge pull request #20007 from DefinitelyMaybe/src/scene--move-to-es6-classes

src/scenes: move to es6 classes
Mr.doob 5 years ago
parent
commit
1819c5b317
3 changed files with 45 additions and 50 deletions
  1. 13 13
      src/scenes/Fog.js
  2. 12 12
      src/scenes/FogExp2.js
  3. 20 25
      src/scenes/Scene.js

+ 13 - 13
src/scenes/Fog.js

@@ -1,27 +1,25 @@
 import { Color } from '../math/Color.js';
 
-function Fog( color, near, far ) {
+class Fog {
 
-	this.name = '';
+	constructor( color, near, far ) {
 
-	this.color = new Color( color );
+		this.name = '';
 
-	this.near = ( near !== undefined ) ? near : 1;
-	this.far = ( far !== undefined ) ? far : 1000;
+		this.color = new Color( color );
 
-}
-
-Object.assign( Fog.prototype, {
+		this.near = ( near !== undefined ) ? near : 1;
+		this.far = ( far !== undefined ) ? far : 1000;
 
-	isFog: true,
+	}
 
-	clone: function () {
+	clone() {
 
 		return new Fog( this.color, this.near, this.far );
 
-	},
+	}
 
-	toJSON: function ( /* meta */ ) {
+	toJSON( /* meta */ ) {
 
 		return {
 			type: 'Fog',
@@ -32,6 +30,8 @@ Object.assign( Fog.prototype, {
 
 	}
 
-} );
+}
+
+Fog.prototype.isFog = true;
 
 export { Fog };

+ 12 - 12
src/scenes/FogExp2.js

@@ -1,25 +1,23 @@
 import { Color } from '../math/Color.js';
 
-function FogExp2( color, density ) {
+class FogExp2 {
 
-	this.name = '';
+	constructor( color, density ) {
 
-	this.color = new Color( color );
-	this.density = ( density !== undefined ) ? density : 0.00025;
+		this.name = '';
 
-}
-
-Object.assign( FogExp2.prototype, {
+		this.color = new Color( color );
+		this.density = ( density !== undefined ) ? density : 0.00025;
 
-	isFogExp2: true,
+	}
 
-	clone: function () {
+	clone() {
 
 		return new FogExp2( this.color, this.density );
 
-	},
+	}
 
-	toJSON: function ( /* meta */ ) {
+	toJSON( /* meta */ ) {
 
 		return {
 			type: 'FogExp2',
@@ -29,6 +27,8 @@ Object.assign( FogExp2.prototype, {
 
 	}
 
-} );
+}
+
+FogExp2.prototype.isFogExp2 = true;
 
 export { FogExp2 };

+ 20 - 25
src/scenes/Scene.js

@@ -1,36 +1,31 @@
 import { Object3D } from '../core/Object3D.js';
 
-function Scene() {
+class Scene extends Object3D {
 
-	Object3D.call( this );
+	constructor() {
 
-	this.type = 'Scene';
+		super();
+		this.type = 'Scene';
 
-	this.background = null;
-	this.environment = null;
-	this.fog = null;
+		this.background = null;
+		this.environment = null;
+		this.fog = null;
 
-	this.overrideMaterial = null;
+		this.overrideMaterial = null;
 
-	this.autoUpdate = true; // checked by the renderer
+		this.autoUpdate = true; // checked by the renderer
 
-	if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
+		if ( typeof __THREE_DEVTOOLS__ !== 'undefined' ) {
 
-		__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
+			__THREE_DEVTOOLS__.dispatchEvent( new CustomEvent( 'observe', { detail: this } ) ); // eslint-disable-line no-undef
 
-	}
-
-}
-
-Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
-
-	constructor: Scene,
+		}
 
-	isScene: true,
+	}
 
-	copy: function ( source, recursive ) {
+	copy( source, recursive ) {
 
-		Object3D.prototype.copy.call( this, source, recursive );
+		super.copy( source, recursive );
 
 		if ( source.background !== null ) this.background = source.background.clone();
 		if ( source.environment !== null ) this.environment = source.environment.clone();
@@ -43,11 +38,11 @@ Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 		return this;
 
-	},
+	}
 
-	toJSON: function ( meta ) {
+	toJSON( meta ) {
 
-		const data = Object3D.prototype.toJSON.call( this, meta );
+		const data = super.toJSON( meta );
 
 		if ( this.background !== null ) data.object.background = this.background.toJSON( meta );
 		if ( this.environment !== null ) data.object.environment = this.environment.toJSON( meta );
@@ -57,8 +52,8 @@ Scene.prototype = Object.assign( Object.create( Object3D.prototype ), {
 
 	}
 
-} );
-
+}
 
+Scene.prototype.isScene = true;
 
 export { Scene };