webgl_loader_texture_basis.html 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - basis texture loader</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <link type="text/css" rel="stylesheet" href="main.css">
  8. </head>
  9. <body>
  10. <div id="info">
  11. <a href="https://threejs.org" target="_blank" rel="noopener">three.js</a> - webgl - basis texture loader<br />
  12. <a href="https://github.com/binomialLLC/basis_universal" target="_blank">Basis Universal GPU Texture Codec</a>
  13. </div>
  14. <script type="module">
  15. import * as THREE from '../build/three.module.js';
  16. import { BasisTextureLoader } from './jsm/loaders/BasisTextureLoader.js';
  17. var camera, scene, renderer;
  18. var mesh;
  19. var clock = new THREE.Clock();
  20. init();
  21. animate();
  22. function init() {
  23. renderer = new THREE.WebGLRenderer( { antialias: true } );
  24. renderer.setPixelRatio( window.devicePixelRatio );
  25. renderer.setSize( window.innerWidth, window.innerHeight );
  26. renderer.outputEncoding = THREE.sRGBEncoding;
  27. document.body.appendChild( renderer.domElement );
  28. camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 2000 );
  29. camera.position.z = 500;
  30. scene = new THREE.Scene();
  31. var geometry = new THREE.BoxBufferGeometry( 200, 200, 200 );
  32. var material = new THREE.MeshBasicMaterial();
  33. mesh = new THREE.Mesh( geometry, material );
  34. scene.add( mesh );
  35. var loader = new BasisTextureLoader();
  36. loader.setTranscoderPath( 'js/libs/basis/' );
  37. loader.detectSupport( renderer );
  38. loader.load( 'textures/compressed/PavingStones.basis', function ( texture ) {
  39. texture.encoding = THREE.sRGBEncoding;
  40. material.map = texture;
  41. material.needsUpdate = true;
  42. }, undefined, function ( error ) {
  43. console.error( error );
  44. } );
  45. window.addEventListener( 'resize', onWindowResize, false );
  46. }
  47. function onWindowResize() {
  48. camera.aspect = window.innerWidth / window.innerHeight;
  49. camera.updateProjectionMatrix();
  50. renderer.setSize( window.innerWidth, window.innerHeight );
  51. }
  52. function animate() {
  53. requestAnimationFrame( animate );
  54. var delta = clock.getDelta() * 0.5;
  55. mesh.rotation.x += delta;
  56. mesh.rotation.y += delta;
  57. renderer.render( scene, camera );
  58. }
  59. </script>
  60. </body>
  61. </html>