|
| 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-10-27 --> |
| 10 | + <meta http-equiv="origin-trial" data-feature="WebXR Device API (For Chrome M69+)" data-expires="2018-10-27" content="An4ZYOGvf6kVHNxqZxS02TPAvpZESkmBhcVCM/byViDDuEB2XKvCF43aCJjrAU/R8H3WDlv+1bDGTL/XxstHGgoAAABTeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkRldmljZU02OSIsImV4cGlyeSI6MTU0MDY1NTAyMn0="> |
| 11 | + <!-- Origin Trial Token, feature = WebXR Gamepad Support, origin = https://threejs.org, expires = 2018-10-24 --> |
| 12 | + <meta http-equiv="origin-trial" data-feature="WebXR Gamepad Support" data-expires="2018-10-24" content="Agrr6lZhlwzv5jmv/mpLZA37DIiVcg3HvX8bH8EWB+OBruV3sUJuzDfYz6qs/je+LcH41DkrmPn4k9RaUaqpQAAAAABYeyJvcmlnaW4iOiJodHRwczovL3RocmVlanMub3JnOjQ0MyIsImZlYXR1cmUiOiJXZWJYUkdhbWVwYWRTdXBwb3J0IiwiZXhwaXJ5IjoxNTQwMzg4NjI0fQ=="> |
| 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 | + |
| 28 | + <script src="../build/three.js"></script> |
| 29 | + <script src="js/vr/WebVR.js"></script> |
| 30 | + <script src="js/geometries/BoxLineGeometry.js"></script> |
| 31 | + |
| 32 | + <script> |
| 33 | + |
| 34 | + var size = 10; |
| 35 | + |
| 36 | + var container; |
| 37 | + var camera, scene, raycaster, renderer; |
| 38 | + |
| 39 | + var room; |
| 40 | + |
| 41 | + init(); |
| 42 | + animate(); |
| 43 | + |
| 44 | + function init() { |
| 45 | + |
| 46 | + container = document.createElement( 'div' ); |
| 47 | + document.body.appendChild( container ); |
| 48 | + |
| 49 | + var info = document.createElement( 'div' ); |
| 50 | + info.style.position = 'absolute'; |
| 51 | + info.style.top = '10px'; |
| 52 | + info.style.width = '100%'; |
| 53 | + info.style.textAlign = 'center'; |
| 54 | + info.innerHTML = '<a href="http://threejs.org" target="_blank" rel="noopener">three.js</a> webgl - interactive cubes'; |
| 55 | + container.appendChild( info ); |
| 56 | + |
| 57 | + scene = new THREE.Scene(); |
| 58 | + scene.background = new THREE.Color( 0x505050 ); |
| 59 | + |
| 60 | + camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 0.1, 10 ); |
| 61 | + scene.add( camera ); |
| 62 | + |
| 63 | + room = new THREE.LineSegments( |
| 64 | + new THREE.BoxLineGeometry( 6, 6, 6, 10, 10, 10 ), |
| 65 | + new THREE.LineBasicMaterial( { color: 0x808080 } ) |
| 66 | + ); |
| 67 | + room.position.y = 3; |
| 68 | + scene.add( room ); |
| 69 | + |
| 70 | + scene.add( new THREE.HemisphereLight( 0x606060, 0x404040 ) ); |
| 71 | + |
| 72 | + var geometry = new THREE.BoxBufferGeometry( 0.15, 0.15, 0.15 ); |
| 73 | + |
| 74 | + for ( var x = 0; x < size; x ++ ) { |
| 75 | + for ( var y = 0; y < size; y ++ ) { |
| 76 | + |
| 77 | + var xVal = x / size; |
| 78 | + var yVal = y / size; |
| 79 | + var color = new THREE.Color( 1, 1, 1 ); |
| 80 | + color.r = x % 2; |
| 81 | + color.g = y % 2; |
| 82 | + color.b = 1; |
| 83 | + var object = new THREE.Mesh( geometry, new THREE.MeshBasicMaterial( { color: color } )); |
| 84 | + |
| 85 | + object.position.x = xVal * 8 - 4; |
| 86 | + object.position.y = yVal * 8 - 4; |
| 87 | + object.position.z = -4; |
| 88 | + |
| 89 | + room.add( object ); |
| 90 | + |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + renderer = new THREE.WebGLRenderer( { antialias: true } ); |
| 95 | + renderer.setPixelRatio( window.devicePixelRatio ); |
| 96 | + renderer.setSize( window.innerWidth, window.innerHeight ); |
| 97 | + renderer.vr.enabled = true; |
| 98 | + container.appendChild( renderer.domElement ); |
| 99 | + |
| 100 | + window.addEventListener( 'resize', onWindowResize, false ); |
| 101 | + |
| 102 | + document.body.appendChild( WEBVR.createButton( renderer ) ); |
| 103 | + |
| 104 | + } |
| 105 | + |
| 106 | + function onWindowResize() { |
| 107 | + |
| 108 | + camera.aspect = window.innerWidth / window.innerHeight; |
| 109 | + camera.updateProjectionMatrix(); |
| 110 | + |
| 111 | + renderer.setSize( window.innerWidth, window.innerHeight ); |
| 112 | + |
| 113 | + } |
| 114 | + |
| 115 | + function animate() { |
| 116 | + |
| 117 | + renderer.setAnimationLoop( render ); |
| 118 | + |
| 119 | + } |
| 120 | + |
| 121 | + function render() { |
| 122 | + |
| 123 | + renderer.render( scene, camera ); |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + </script> |
| 128 | + </body> |
| 129 | +</html> |
0 commit comments