Skip to content

Commit 0dfb9b0

Browse files
authored
Editor: Store background in IndexedDB (#22023)
* ObjectLoader: Clean up * Object3D: Clean up * Editor: Store background in IndexedDB * Editor: Simplified background handling.
1 parent e9fb8d4 commit 0dfb9b0

File tree

5 files changed

+35
-23
lines changed

5 files changed

+35
-23
lines changed

editor/js/Editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ Editor.prototype = {
131131
this.scene.uuid = scene.uuid;
132132
this.scene.name = scene.name;
133133

134-
this.scene.background = ( scene.background !== null ) ? scene.background.clone() : null;
134+
this.scene.background = scene.background;
135135

136136
if ( scene.fog !== null ) this.scene.fog = scene.fog.clone();
137137

editor/js/Sidebar.Scene.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as THREE from '../../build/three.module.js';
2+
13
import { UIPanel, UIBreak, UIRow, UIColor, UISelect, UIText, UINumber } from './libs/ui.js';
24
import { UIOutliner, UITexture } from './libs/ui.three.js';
35

@@ -166,7 +168,6 @@ function SidebarScene( editor ) {
166168
refreshBackgroundUI();
167169

168170
} );
169-
backgroundType.setValue( 'Color' );
170171

171172
backgroundRow.add( new UIText( strings.getKey( 'sidebar/scene/background' ) ).setWidth( '90px' ) );
172173
backgroundRow.add( backgroundType );
@@ -376,18 +377,26 @@ function SidebarScene( editor ) {
376377

377378
backgroundType.setValue( 'Color' );
378379
backgroundColor.setHexValue( scene.background.getHex() );
379-
backgroundTexture.setValue( null );
380-
backgroundEquirectangularTexture.setValue( null );
381380

382-
}
381+
} else if ( scene.background.isTexture ) {
382+
383+
if ( scene.background.mapping === THREE.EquirectangularReflectionMapping ) {
384+
385+
backgroundType.setValue( 'Equirectangular' );
386+
backgroundEquirectangularTexture.setValue( scene.background );
387+
388+
} else {
383389

384-
// TODO: Add Texture/EquirectangularTexture support
390+
backgroundType.setValue( 'Texture' );
391+
backgroundTexture.setValue( scene.background );
392+
393+
}
394+
395+
}
385396

386397
} else {
387398

388399
backgroundType.setValue( 'None' );
389-
backgroundTexture.setValue( null );
390-
backgroundEquirectangularTexture.setValue( null );
391400

392401
}
393402

editor/js/Viewport.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -565,11 +565,8 @@ function Viewport( editor ) {
565565

566566
if ( backgroundEquirectangularTexture ) {
567567

568-
var renderTarget = new THREE.WebGLCubeRenderTarget( backgroundEquirectangularTexture.image.width );
569-
renderTarget.fromEquirectangularTexture( renderer, backgroundEquirectangularTexture );
570-
renderTarget.toJSON = function () { return null }; // TODO Remove hack
571-
572-
scene.background = renderTarget.texture;
568+
backgroundEquirectangularTexture.mapping = THREE.EquirectangularReflectionMapping;
569+
scene.background = backgroundEquirectangularTexture;
573570

574571
}
575572

src/core/Object3D.js

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -701,21 +701,27 @@ class Object3D extends EventDispatcher {
701701

702702
if ( this.isScene ) {
703703

704-
if ( this.background && this.background.isColor ) {
704+
if ( this.background ) {
705705

706-
object.background = this.background.toJSON();
706+
if ( this.background.isColor ) {
707707

708-
} else if ( this.background && this.background.isTexture ) {
708+
object.background = this.background.toJSON();
709709

710-
object.background = this.background.toJSON( meta ).uuid;
710+
} else if ( this.background.isTexture ) {
711+
712+
object.background = this.background.toJSON( meta ).uuid;
713+
714+
}
711715

712716
}
713717

714-
if ( this.environment && this.environment.isTexture ) object.environment = this.environment.toJSON( meta ).uuid;
718+
if ( this.environment && this.environment.isTexture ) {
715719

716-
}
720+
object.environment = this.environment.toJSON( meta ).uuid;
721+
722+
}
717723

718-
if ( this.isMesh || this.isLine || this.isPoints ) {
724+
} else if ( this.isMesh || this.isLine || this.isPoints ) {
719725

720726
object.geometry = serialize( meta.geometries, this.geometry );
721727

src/loaders/ObjectLoader.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class ObjectLoader extends Loader {
128128
const textures = this.parseTextures( json.textures, images );
129129
const materials = this.parseMaterials( json.materials, textures );
130130

131-
const object = this.parseObject( json.object, geometries, materials, animations, textures );
131+
const object = this.parseObject( json.object, geometries, materials, textures, animations );
132132
const skeletons = this.parseSkeletons( json.skeletons, object );
133133

134134
this.bindSkeletons( object, skeletons );
@@ -784,7 +784,7 @@ class ObjectLoader extends Loader {
784784

785785
}
786786

787-
parseObject( data, geometries, materials, animations, textures ) {
787+
parseObject( data, geometries, materials, textures, animations ) {
788788

789789
let object;
790790

@@ -1087,7 +1087,7 @@ class ObjectLoader extends Loader {
10871087

10881088
for ( let i = 0; i < children.length; i ++ ) {
10891089

1090-
object.add( this.parseObject( children[ i ], geometries, materials, animations, textures ) );
1090+
object.add( this.parseObject( children[ i ], geometries, materials, textures, animations ) );
10911091

10921092
}
10931093

0 commit comments

Comments
 (0)