浏览代码

Update webgl_panorama_cube.html (#22065)

* Update webgl_panorama_cube.html

* Update webgl_panorama_cube.html

* Update webgl_panorama_cube.html
puxiao 4 年之前
父节点
当前提交
d5c49f58ca
共有 1 个文件被更改,包括 14 次插入17 次删除
  1. 14 17
      examples/webgl_panorama_cube.html

+ 14 - 17
examples/webgl_panorama_cube.html

@@ -73,28 +73,25 @@
 
 				}
 
-				const imageObj = new Image();
+				new THREE.ImageLoader()
+					.load( atlasImgUrl, ( image ) => {
 
-				imageObj.onload = function () {
+						let canvas, context;
+						const tileWidth = image.height;
 
-					let canvas, context;
-					const tileWidth = imageObj.height;
+						for ( let i = 0; i < textures.length; i ++ ) {
 
-					for ( let i = 0; i < textures.length; i ++ ) {
+							canvas = document.createElement( 'canvas' );
+							context = canvas.getContext( '2d' );
+							canvas.height = tileWidth;
+							canvas.width = tileWidth;
+							context.drawImage( image, tileWidth * i, 0, tileWidth, tileWidth, 0, 0, tileWidth, tileWidth );
+							textures[ i ].image = canvas;
+							textures[ i ].needsUpdate = true;
 
-						canvas = document.createElement( 'canvas' );
-						context = canvas.getContext( '2d' );
-						canvas.height = tileWidth;
-						canvas.width = tileWidth;
-						context.drawImage( imageObj, tileWidth * i, 0, tileWidth, tileWidth, 0, 0, tileWidth, tileWidth );
-						textures[ i ].image = canvas;
-						textures[ i ].needsUpdate = true;
+						}
 
-					}
-
-				};
-
-				imageObj.src = atlasImgUrl;
+					} );
 
 				return textures;