webgl_materials_texture_pvrtc.html 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - materials - compressed textures</title>
  5. <meta charset="utf-8">
  6. <style>
  7. body {
  8. margin: 0px;
  9. background-color: #050505;
  10. color: #fff;
  11. overflow: hidden;
  12. }
  13. a { color: #e00 }
  14. #info {
  15. position: absolute;
  16. top: 0px; width: 100%;
  17. color: #ffffff;
  18. padding: 5px;
  19. font-family:Monospace;
  20. font-size:13px;
  21. text-align:center;
  22. z-index:1000;
  23. }
  24. #stats { position: absolute; top:0; left: 0 }
  25. #stats #fps { background: transparent !important }
  26. #stats #fps #fpsText { color: #aaa !important }
  27. #stats #fps #fpsGraph { display: none }
  28. </style>
  29. </head>
  30. <body>
  31. <div id="info">
  32. <a href="http://threejs.org" target="_blank">three.js</a> - webgl - PVR compressed textures
  33. </div>
  34. <script src="../build/three.min.js"></script>
  35. <script src="js/loaders/CompressedTextureLoader.js"></script>
  36. <script src="js/loaders/PVRLoader.js"></script>
  37. <script src="js/Detector.js"></script>
  38. <script src="js/libs/stats.min.js"></script>
  39. <script>
  40. if ( ! Detector.webgl ) Detector.addGetWebGLMessage();
  41. var camera, scene, renderer;
  42. var meshes = [];
  43. init();
  44. animate();
  45. function init() {
  46. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  47. camera.position.z = 1000;
  48. scene = new THREE.Scene();
  49. geometry = new THREE.BoxGeometry( 200, 200, 200 );
  50. /*
  51. */
  52. var onCubeLoaded = function(texture){
  53. texture.magFilter = THREE.LinearFilter
  54. texture.minFilter = THREE.LinearFilter;
  55. texture.mapping = new THREE.CubeReflectionMapping();
  56. material6.needsUpdate = true;
  57. };
  58. var loader = new THREE.PVRLoader();
  59. var disturb_4bpp_rgb = loader.load( 'textures/compressed/disturb_4bpp_rgb.pvr');
  60. var disturb_4bpp_rgb_mips = loader.load( 'textures/compressed/disturb_4bpp_rgb_mips.pvr');
  61. var disturb_2bpp_rgb = loader.load( 'textures/compressed/disturb_2bpp_rgb.pvr');
  62. var flare_4bpp_rgba = loader.load( 'textures/compressed/flare_4bpp_rgba.pvr');
  63. var flare_2bpp_rgba = loader.load( 'textures/compressed/flare_2bpp_rgba.pvr');
  64. var park3_cube_nomip_4bpp_rgb = loader.load( 'textures/compressed/park3_cube_nomip_4bpp_rgb.pvr', onCubeLoaded );
  65. disturb_2bpp_rgb.minFilter =
  66. disturb_2bpp_rgb.magFilter =
  67. flare_4bpp_rgba.minFilter =
  68. flare_4bpp_rgba.magFilter =
  69. disturb_4bpp_rgb.minFilter =
  70. disturb_4bpp_rgb.magFilter =
  71. flare_2bpp_rgba.minFilter =
  72. flare_2bpp_rgba.magFilter = THREE.LinearFilter;
  73. var material1 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb } );
  74. var material2 = new THREE.MeshBasicMaterial( { map: disturb_4bpp_rgb_mips } );
  75. var material3 = new THREE.MeshBasicMaterial( { map: disturb_2bpp_rgb } );
  76. var material4 = new THREE.MeshBasicMaterial( { map: flare_4bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  77. var material5 = new THREE.MeshBasicMaterial( { map: flare_2bpp_rgba , side: THREE.DoubleSide, depthTest: false, transparent: true } );
  78. var material6 = new THREE.MeshBasicMaterial( { envMap: park3_cube_nomip_4bpp_rgb } );
  79. var mesh = new THREE.Mesh( geometry, material1 );
  80. mesh.position.x = -400;
  81. mesh.position.y = 200;
  82. scene.add( mesh );
  83. meshes.push( mesh );
  84. mesh = new THREE.Mesh( geometry, material2 );
  85. mesh.position.x = 0;
  86. mesh.position.y = 200;
  87. scene.add( mesh );
  88. meshes.push( mesh );
  89. mesh = new THREE.Mesh( geometry, material3 );
  90. mesh.position.x = 400;
  91. mesh.position.y = 200;
  92. scene.add( mesh );
  93. meshes.push( mesh );
  94. mesh = new THREE.Mesh( geometry, material4 );
  95. mesh.position.x = -400;
  96. mesh.position.y = -200;
  97. scene.add( mesh );
  98. meshes.push( mesh );
  99. mesh = new THREE.Mesh( geometry, material5 );
  100. mesh.position.x = 0;
  101. mesh.position.y = -200;
  102. scene.add( mesh );
  103. meshes.push( mesh );
  104. mesh = new THREE.Mesh( new THREE.TorusGeometry( 100, 50, 32, 16 ), material6 );
  105. mesh.position.x = 400;
  106. mesh.position.y = -200;
  107. scene.add( mesh );
  108. meshes.push( mesh );
  109. renderer = new THREE.WebGLRenderer( { antialias: true } );
  110. renderer.setSize( window.innerWidth, window.innerHeight );
  111. document.body.appendChild( renderer.domElement );
  112. stats = new Stats();
  113. document.body.appendChild( stats.domElement );
  114. window.addEventListener( 'resize', onWindowResize, false );
  115. }
  116. function onWindowResize() {
  117. camera.aspect = window.innerWidth / window.innerHeight;
  118. camera.updateProjectionMatrix();
  119. renderer.setSize( window.innerWidth, window.innerHeight );
  120. }
  121. function animate() {
  122. requestAnimationFrame( animate );
  123. var time = Date.now() * 0.001;
  124. for ( var i = 0; i < meshes.length; i ++ ) {
  125. var mesh = meshes[ i ];
  126. mesh.rotation.x = time;
  127. mesh.rotation.y = time;
  128. }
  129. renderer.render( scene, camera );
  130. stats.update();
  131. }
  132. </script>
  133. </body>
  134. </html>
粤ICP备19079148号