Browse Source

Merge pull request #18966 from Mugen87/dev48

LightProbe: Add support for serialization/deserialization.
Mr.doob 5 năm trước cách đây
mục cha
commit
d26c835050
3 tập tin đã thay đổi với 21 bổ sung2 xóa
  1. 2 0
      src/lights/LightProbe.d.ts
  2. 12 2
      src/lights/LightProbe.js
  3. 7 0
      src/loaders/ObjectLoader.js

+ 2 - 0
src/lights/LightProbe.d.ts

@@ -8,4 +8,6 @@ export class LightProbe extends Light {
 	readonly isLightProbe: true;
 	sh: SphericalHarmonics3;
 
+	fromJSON( json: object ): LightProbe;
+
 }

+ 12 - 2
src/lights/LightProbe.js

@@ -11,6 +11,8 @@ function LightProbe( sh, intensity ) {
 
 	Light.call( this, undefined, intensity );
 
+	this.type = 'LightProbe';
+
 	this.sh = ( sh !== undefined ) ? sh : new SphericalHarmonics3();
 
 }
@@ -26,7 +28,15 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
 		Light.prototype.copy.call( this, source );
 
 		this.sh.copy( source.sh );
-		this.intensity = source.intensity;
+
+		return this;
+
+	},
+
+	fromJSON: function ( json ) {
+
+		this.intensity = json.intensity; // TODO: Move this bit to Light.fromJSON();
+		this.sh.fromArray( json.sh );
 
 		return this;
 
@@ -36,7 +46,7 @@ LightProbe.prototype = Object.assign( Object.create( Light.prototype ), {
 
 		var data = Light.prototype.toJSON.call( this, meta );
 
-		// data.sh = this.sh.toArray(); // todo
+		data.object.sh = this.sh.toArray();
 
 		return data;
 

+ 7 - 0
src/loaders/ObjectLoader.js

@@ -40,6 +40,7 @@ import { PointLight } from '../lights/PointLight.js';
 import { DirectionalLight } from '../lights/DirectionalLight.js';
 import { AmbientLight } from '../lights/AmbientLight.js';
 import { RectAreaLight } from '../lights/RectAreaLight.js';
+import { LightProbe } from '../lights/LightProbe.js';
 import { OrthographicCamera } from '../cameras/OrthographicCamera.js';
 import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
 import { Scene } from '../scenes/Scene.js';
@@ -817,6 +818,12 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
 
 				break;
 
+			case 'LightProbe':
+
+				object = new LightProbe().fromJSON( data );
+
+				break;
+
 			case 'SkinnedMesh':
 
 				console.warn( 'THREE.ObjectLoader.parseObject() does not support SkinnedMesh yet.' );