webgl_loader_callbacks.html 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  6. <title>three.js webgl - loader callbacks</title>
  7. <style>
  8. body {
  9. margin: 0;
  10. font-family: Arial;
  11. overflow: hidden;
  12. }
  13. a {
  14. color: #ffffff;
  15. }
  16. #info {
  17. position: absolute;
  18. top: 0px;
  19. width: 100%;
  20. color: #ffffff;
  21. padding: 5px;
  22. font-family: Monospace;
  23. font-size: 13px;
  24. font-weight: bold;
  25. text-align: center;
  26. z-index: 1;
  27. }
  28. #menu {
  29. position: absolute;
  30. bottom: 20px;
  31. width: 100%;
  32. text-align: center;
  33. padding: 0;
  34. margin: 0;
  35. }
  36. button {
  37. color: rgb(255,255,255);
  38. background: transparent;
  39. border: 0px;
  40. padding: 5px 10px;
  41. cursor: pointer;
  42. }
  43. button:hover {
  44. background-color: rgba(0,255,255,0.5);
  45. }
  46. button:active {
  47. color: #000000;
  48. background-color: rgba(0,255,255,1);
  49. }
  50. .bond {
  51. width: 5px;
  52. height: 10px;
  53. background: #eee;
  54. display: block;
  55. }
  56. </style>
  57. </head>
  58. <body>
  59. <script src="../build/three.js"></script>
  60. <script src="js/controls/TrackballControls.js"></script>
  61. <div id="container"></div>
  62. <div id="info"><a href="http://threejs.org" target="_blank">three.js webgl</a> - molecules</div>
  63. <script>
  64. var camera, scene, renderer;
  65. var controls;
  66. init();
  67. animate();
  68. function init() {
  69. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 5000 );
  70. camera.position.z = 3;
  71. scene = new THREE.Scene();
  72. var light = new THREE.HemisphereLight( 0xffffff, 0x000000 );
  73. light.position.set( 1, 1, 1 );
  74. scene.add( light );
  75. //
  76. renderer = new THREE.WebGLRenderer( { antialias: true } );
  77. renderer.setClearColor( 0x050505 );
  78. renderer.setSize( window.innerWidth, window.innerHeight );
  79. document.getElementById( 'container' ).appendChild( renderer.domElement );
  80. //
  81. controls = new THREE.TrackballControls( camera, renderer.domElement );
  82. controls.rotateSpeed = 0.5;
  83. controls.addEventListener( 'change', render );
  84. window.addEventListener( 'resize', onWindowResize, false );
  85. var textureLoader = new THREE.TextureLoader()
  86. textureLoader.load('textures/crate.gif', function(texture) {
  87. console.log('texture loaded')
  88. var material = new THREE.SpriteMaterial({ map: texture, color: 0xffffff, useScreenCoordinates: false})
  89. var sp = new THREE.Sprite(material);
  90. scene.add(sp)
  91. }, function(progress) {
  92. console.log('do we have progress?')
  93. })
  94. textureLoader.load('textures/404-texture-doesnt-exist.bmp', function(texture) {
  95. },function () {
  96. //progress callback
  97. }, function (error) {
  98. console.log('error caught - image not loaded')
  99. console.log(error)
  100. })
  101. }
  102. //
  103. function onWindowResize() {
  104. camera.aspect = window.innerWidth / window.innerHeight;
  105. camera.updateProjectionMatrix();
  106. renderer.setSize( window.innerWidth, window.innerHeight );
  107. render();
  108. }
  109. function animate() {
  110. requestAnimationFrame( animate );
  111. controls.update();
  112. render();
  113. }
  114. function render() {
  115. renderer.render( scene, camera );
  116. }
  117. </script>
  118. </body>
  119. </html>