Skip to content

Commit 2f3dd38

Browse files
committed
Editor: Load image loaders only when needed.
1 parent 01d3c94 commit 2f3dd38

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

editor/js/libs/ui.three.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import * as THREE from 'three';
22

3-
import { EXRLoader } from 'three/addons/loaders/EXRLoader.js';
4-
import { KTX2Loader } from 'three/addons/loaders/KTX2Loader.js';
5-
import { RGBELoader } from 'three/addons/loaders/RGBELoader.js';
6-
import { TGALoader } from 'three/addons/loaders/TGALoader.js';
73
import { FullScreenQuad } from 'three/addons/postprocessing/Pass.js';
84

95
import { UISpan, UIDiv, UIRow, UIButton, UICheckbox, UIText, UINumber } from './ui.js';
@@ -50,7 +46,7 @@ class UITexture extends UISpan {
5046
} );
5147
this.dom.appendChild( canvas );
5248

53-
function loadFile( file ) {
49+
async function loadFile( file ) {
5450

5551
const extension = file.name.split( '.' ).pop().toLowerCase();
5652
const reader = new FileReader();
@@ -67,10 +63,12 @@ class UITexture extends UISpan {
6763

6864
} else if ( extension === 'hdr' || extension === 'pic' ) {
6965

70-
reader.addEventListener( 'load', function ( event ) {
66+
reader.addEventListener( 'load', async function ( event ) {
7167

7268
// assuming RGBE/Radiance HDR image format
7369

70+
const { RGBELoader } = await import( 'three/addons/loaders/RGBELoader.js' );
71+
7472
const loader = new RGBELoader();
7573
loader.load( event.target.result, function ( hdrTexture ) {
7674

@@ -90,7 +88,9 @@ class UITexture extends UISpan {
9088

9189
} else if ( extension === 'tga' ) {
9290

93-
reader.addEventListener( 'load', function ( event ) {
91+
reader.addEventListener( 'load', async function ( event ) {
92+
93+
const { TGALoader } = await import( 'three/addons/loaders/TGALoader.js' );
9494

9595
const loader = new TGALoader();
9696
loader.load( event.target.result, function ( texture ) {
@@ -113,7 +113,9 @@ class UITexture extends UISpan {
113113

114114
} else if ( extension === 'ktx2' ) {
115115

116-
reader.addEventListener( 'load', function ( event ) {
116+
reader.addEventListener( 'load', async function ( event ) {
117+
118+
const { KTX2Loader } = await import( 'three/addons/loaders/KTX2Loader.js' );
117119

118120
const arrayBuffer = event.target.result;
119121
const blobURL = URL.createObjectURL( new Blob( [ arrayBuffer ] ) );
@@ -142,7 +144,9 @@ class UITexture extends UISpan {
142144

143145
} else if ( extension === 'exr' ) {
144146

145-
reader.addEventListener( 'load', function ( event ) {
147+
reader.addEventListener( 'load', async function ( event ) {
148+
149+
const { EXRLoader } = await import( 'three/addons/loaders/EXRLoader.js' );
146150

147151
const arrayBuffer = event.target.result;
148152
const blobURL = URL.createObjectURL( new Blob( [ arrayBuffer ] ) );

0 commit comments

Comments
 (0)