提交 4aa9e46f 编写于 作者: M Mr.doob

Cleaned up ImageBitmapLoader example.

上级 ceb88071
...@@ -59,9 +59,9 @@ ...@@ -59,9 +59,9 @@
<div id="info"> <div id="info">
<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - Texture loader using ImageBitmap <a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> - Texture loader using ImageBitmap
<div class="actions"> <div class="actions">
<span id="add_ib_btn" >Press to add ImageBitmap</span> <span id="add_ib_btn">Add ImageBitmap</span>
<span id="add_i_btn">Press to add Image</span> <span id="add_i_btn">Add Image</span>
<span id="clear_btn" >Clear</span> <span id="clear_btn">Clear</span>
</div> </div>
</div> </div>
...@@ -77,53 +77,49 @@ ...@@ -77,53 +77,49 @@
var camera, scene, renderer; var camera, scene, renderer;
var group, cubes; var group, cubes;
var autoAddImageBitmap = false;
var autoAddImage = false;
init(); init();
animate(); animate();
function addImageBitmap () { function addImageBitmap () {
new THREE.ImageBitmapLoader() new THREE.ImageBitmapLoader()
.setOptions( { imageOrientation: 'none' } ) .setOptions( { imageOrientation: 'none' } )
.load ( 'textures/planets/earth_atmos_2048.jpg', function( imageBitmap ) { .load( 'textures/planets/earth_atmos_2048.jpg', function( imageBitmap ) {
var tex = new THREE.Texture ( imageBitmap ); var tex = new THREE.CanvasTexture( imageBitmap );
tex.needsUpdate = true;
/* ImageBitmap should be disposed when done with it /* ImageBitmap should be disposed when done with it
Can't be done until it's actually uploaded to WebGLTexture */ Can't be done until it's actually uploaded to WebGLTexture */
// imageBitmap.close(); // imageBitmap.close();
addCube( tex ); addCube( tex );
}, function( p ) { }, function( p ) {
console.log( p ); console.log( p );
}, function( e ) { }, function( e ) {
console.log( e ); console.log( e );
} ); } );
} }
function addImage () { function addImage () {
new THREE.ImageLoader()
new THREE.TextureLoader().load( 'textures/planets/earth_atmos_2048.jpg?' + performance.now(), function( tex ) { .load( 'textures/planets/earth_atmos_2048.jpg?' + performance.now(), function( image ) {
addCube( tex ); var tex = new THREE.CanvasTexture( image );
addCube( tex );
}); });
} }
function addCube ( texture ) { var geometry = new THREE.BoxBufferGeometry( 1,1,1 );
function addCube( texture ) {
var material = new THREE.MeshBasicMaterial( { map: texture } );
var cube = new THREE.Mesh( var cube = new THREE.Mesh( geometry, material );
new THREE.BoxBufferGeometry( 1,1,1 ),
new THREE.MeshBasicMaterial( {
map: texture
})
);
cube.position.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 ); cube.position.set( Math.random() * 2 - 1, Math.random() * 2 - 1, Math.random() * 2 - 1 );
cube.rotation.set( Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI ); cube.rotation.set( Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI, Math.random() * 2 * Math.PI );
cubes.add( cube ); cubes.add( cube );
...@@ -199,12 +195,12 @@ ...@@ -199,12 +195,12 @@
function animate() { function animate() {
requestAnimationFrame( animate ); group.rotation.y = performance.now() / 3000;
group.rotation.y = performance.now() / 2000;
renderer.render( scene, camera ); renderer.render( scene, camera );
requestAnimationFrame( animate );
} }
</script> </script>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册