webgl_video_panorama_equirectangular.html 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webgl - equirectangular video panorama</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. <style>
  8. body {
  9. background-color: #000000;
  10. margin: 0px;
  11. overflow: hidden;
  12. }
  13. #info {
  14. position: absolute;
  15. top: 0px; width: 100%;
  16. color: #ffffff;
  17. padding: 5px;
  18. font-family:Monospace;
  19. font-size:13px;
  20. font-weight: bold;
  21. text-align:center;
  22. }
  23. a {
  24. color: #ffffff;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div id="container"></div>
  30. <script src="../build/three.js"></script>
  31. <script>
  32. var camera, scene, renderer;
  33. var texture_placeholder,
  34. isUserInteracting = false,
  35. onMouseDownMouseX = 0, onMouseDownMouseY = 0,
  36. lon = 0, onMouseDownLon = 0,
  37. lat = 0, onMouseDownLat = 0,
  38. phi = 0, theta = 0,
  39. distance = 500,
  40. onPointerDownPointerX = 0,
  41. onPointerDownPointerY = 0,
  42. onPointerDownLon = 0,
  43. onPointerDownLat = 0;
  44. init();
  45. animate();
  46. function init() {
  47. var container, mesh;
  48. container = document.getElementById( 'container' );
  49. camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 1100 );
  50. camera.target = new THREE.Vector3( 0, 0, 0 );
  51. scene = new THREE.Scene();
  52. var geometry = new THREE.SphereBufferGeometry( 500, 60, 40 );
  53. geometry.scale( - 1, 1, 1 );
  54. var video = document.createElement( 'video' );
  55. video.width = 640;
  56. video.height = 360;
  57. video.loop = true;
  58. video.muted = true;
  59. video.src = "textures/pano.webm";
  60. video.setAttribute( 'webkit-playsinline', 'webkit-playsinline' );
  61. video.play();
  62. var texture = new THREE.VideoTexture( video );
  63. texture.minFilter = THREE.LinearFilter;
  64. texture.format = THREE.RGBFormat;
  65. var material = new THREE.MeshBasicMaterial( { map : texture } );
  66. mesh = new THREE.Mesh( geometry, material );
  67. scene.add( mesh );
  68. renderer = new THREE.WebGLRenderer();
  69. renderer.setPixelRatio( window.devicePixelRatio );
  70. renderer.setSize( window.innerWidth, window.innerHeight );
  71. container.appendChild( renderer.domElement );
  72. document.addEventListener( 'mousedown', onDocumentMouseDown, false );
  73. document.addEventListener( 'mousemove', onDocumentMouseMove, false );
  74. document.addEventListener( 'mouseup', onDocumentMouseUp, false );
  75. document.addEventListener( 'wheel', onDocumentMouseWheel, false );
  76. //
  77. window.addEventListener( 'resize', onWindowResize, false );
  78. }
  79. function onWindowResize() {
  80. camera.aspect = window.innerWidth / window.innerHeight;
  81. camera.updateProjectionMatrix();
  82. renderer.setSize( window.innerWidth, window.innerHeight );
  83. }
  84. function onDocumentMouseDown( event ) {
  85. event.preventDefault();
  86. isUserInteracting = true;
  87. onPointerDownPointerX = event.clientX;
  88. onPointerDownPointerY = event.clientY;
  89. onPointerDownLon = lon;
  90. onPointerDownLat = lat;
  91. }
  92. function onDocumentMouseMove( event ) {
  93. if ( isUserInteracting === true ) {
  94. lon = ( onPointerDownPointerX - event.clientX ) * 0.1 + onPointerDownLon;
  95. lat = ( event.clientY - onPointerDownPointerY ) * 0.1 + onPointerDownLat;
  96. }
  97. }
  98. function onDocumentMouseUp( event ) {
  99. isUserInteracting = false;
  100. }
  101. function onDocumentMouseWheel( event ) {
  102. distance += event.deltaY * 0.05;
  103. }
  104. function animate() {
  105. requestAnimationFrame( animate );
  106. update();
  107. }
  108. function update() {
  109. lat = Math.max( - 85, Math.min( 85, lat ) );
  110. phi = THREE.Math.degToRad( 90 - lat );
  111. theta = THREE.Math.degToRad( lon );
  112. camera.position.x = distance * Math.sin( phi ) * Math.cos( theta );
  113. camera.position.y = distance * Math.cos( phi );
  114. camera.position.z = distance * Math.sin( phi ) * Math.sin( theta );
  115. camera.lookAt( camera.target );
  116. /*
  117. // distortion
  118. camera.position.copy( camera.target ).negate();
  119. */
  120. renderer.render( scene, camera );
  121. }
  122. </script>
  123. </body>
  124. </html>