webvr_frustum.html 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>three.js webvr - frustum</title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
  7. <!-- Origin Trial Token, feature = WebVR (For Chrome M62+), origin = https://threejs.org, expires = 2018-09-11 -->
  8. <meta http-equiv="origin-trial" data-feature="WebVR (For Chrome M62+)" data-expires="2018-09-11" content="AqhFUYKxq/d+E8CDT0fuYRCg8TvlTP52x0Jv7I9t27sLhR30LmcahBRfSwzP89ukjs2+ia99VrrLoRyaFAwJVA0AAABQeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJWUjEuMU02MiIsImV4cGlyeSI6MTUzNjYyNDAwMH0=">
  9. <!-- Origin Trial Token, feature = WebXR Device API (For Chrome M69+), origin = https://threejs.org, expires = 2018-12-02 -->
  10. <meta http-equiv="origin-trial" data-feature="WebXR Device API (For Chrome M69+)" data-expires="2018-12-02" content="Ah46myef4Ax/+fcLtkeotXmIqnvun4lg4bYbHVttuJvbsWiE4oacrvroId7hbCEb4/byxFHIO6+uwq4pwr6RfQkAAABTeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZU02OSIsImV4cGlyeSI6MTU0Mzc1ODIyNn0=">
  11. <!-- Origin Trial Token, feature = WebXR Gamepad Support, origin = https://threejs.org, expires = 2018-12-02 -->
  12. <meta http-equiv="origin-trial" data-feature="WebXR Gamepad Support" data-expires="2018-12-02" content="AqI9LIanbGxr/HoTOsYCUNxG82Vy94NZbjhv83R+bF+5NX2jiZOaf7ny+mFoTUP5wrWpYlPjQ6+HeVas9f1lRwYAAABYeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkdhbWVwYWRTdXBwb3J0IiwiZXhwaXJ5IjoxNTQzNzU4MjI2fQ==">
  13. <style>
  14. body {
  15. font-family: Monospace;
  16. background-color: #101010;
  17. color: #fff;
  18. margin: 0px;
  19. overflow: hidden;
  20. }
  21. a {
  22. color: #f00;
  23. }
  24. </style>
  25. </head>
  26. <body>
  27. <script src="../build/three.js"></script>
  28. <script src="js/vr/WebVR.js"></script>
  29. <script src="js/geometries/BoxLineGeometry.js"></script>
  30. <script>
  31. var size = 10;
  32. var container;
  33. var camera, scene, raycaster, renderer;
  34. var room;
  35. init();
  36. animate();
  37. function init() {
  38. container = document.createElement( 'div' );
  39. document.body.appendChild( container );
  40. var info = document.createElement( 'div' );
  41. info.style.position = 'absolute';
  42. info.style.top = '10px';
  43. info.style.width = '100%';
  44. info.style.textAlign = 'center';
  45. info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - interactive cubes';
  46. container.appendChild( info );
  47. scene = new THREE.Scene();
  48. scene.background = new THREE.Color( 0x505050 );
  49. camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 );
  50. scene.add( camera );
  51. room = new THREE.LineSegments(
  52. new THREE.BoxLineGeometry( 6, 6, 6, 10, 10, 10 ),
  53. new THREE.LineBasicMaterial( { color: 0x808080 } )
  54. );
  55. room.position.y = 3;
  56. scene.add( room );
  57. scene.add( new THREE.HemisphereLight( 0x606060, 0x404040 ) );
  58. var geometry = new THREE.BoxBufferGeometry( 0.15, 0.15, 0.15 );
  59. for ( var x = 0; x < size; x ++ ) {
  60. for ( var y = 0; y < size; y ++ ) {
  61. var xVal = x / size;
  62. var yVal = y / size;
  63. var color = new THREE.Color( 1, 1, 1 );
  64. color.r = x % 2;
  65. color.g = y % 2;
  66. color.b = 1;
  67. var object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: color } ));
  68. object.position.x = xVal * 8 - 4;
  69. object.position.y = yVal * 8 - 4;
  70. object.position.z = -4;
  71. room.add( object );
  72. }
  73. }
  74. renderer = new THREE.WebGLRenderer( { antialias: true } );
  75. renderer.setPixelRatio( window.devicePixelRatio );
  76. renderer.setSize( window.innerWidth, window.innerHeight );
  77. renderer.vr.enabled = true;
  78. container.appendChild( renderer.domElement );
  79. window.addEventListener( 'resize', onWindowResize, false );
  80. document.body.appendChild( WEBVR.createButton( renderer ) );
  81. }
  82. function onWindowResize() {
  83. camera.aspect = window.innerWidth / window.innerHeight;
  84. camera.updateProjectionMatrix();
  85. renderer.setSize( window.innerWidth, window.innerHeight );
  86. }
  87. function animate() {
  88. renderer.setAnimationLoop( render );
  89. }
  90. function render() {
  91. renderer.render( scene, camera );
  92. }
  93. </script>
  94. </body>
  95. </html>