-
Notifications
You must be signed in to change notification settings - Fork 3
/
example.html
109 lines (93 loc) · 2.9 KB
/
example.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
<html>
<head>
<title>Threejs VRSetup.js Example</title>
<!----------------------------------
-- THREEJS and supporting libraries
------------------------------------>
<script src="./jquery-1.11.1.min.js"></script>
<script src="./three.js"></script>
<!----------------------------------
-- Don't forget to include VRSetup!
------------------------------------>
<script src="./VRSetup.js"></script>
<!----------------------------------
-- Some styling to make it less ugly
------------------------------------>
<style>
body
{
font-family: Monospace;
font-weight: bold;
background-color: #ccccff;
margin: 0px;
overflow: hidden;
}
</style>
<script>
//Global references
var g_scene, g_renderer;
//Handle to the VRSetup object
var g_vr;
$( document ).ready( function(){
/*************************************
* Boilerplate THREEJS scene setup
**************************************/
this.containerEle = $(".threejs-container").get(0);
// SCENE
this.scene = new THREE.Scene();
g_scene = this.scene;
this.SCREEN_WIDTH = window.innerWidth;
this.SCREEN_HEIGHT = window.innerHeight;
//RENDERER
this.renderer = new THREE.WebGLRenderer({antialias:true});
g_renderer = this.renderer;
this.renderer.setSize(this.SCREEN_WIDTH, this.SCREEN_HEIGHT);
this.containerEle.appendChild( g_renderer.domElement );
/************************************
* Render a cube and a light
*************************************/
// LIGHT
var light = new THREE.AmbientLight( 0x404040 );
g_scene.add( light );
// CUBE: cute, not ugly
var cute_cube = new THREE.Mesh(new THREE.BoxGeometry(1,1,1), new THREE.MeshLambertMaterial( {color: 0x8888ff} ));
cute_cube.position.set(6,-7,-18);
g_scene.add( cute_cube );
/************************************
* Initialize the VRSetup object
*************************************/
g_vr = new VRSetup(g_renderer, g_scene);
/************************************
* Enable the VR
*************************************/
$("#start-button").click(function() {
g_vr.RequestFullScreenVR();
});
/************************************
* Kick off the animation loop!
*************************************/
animate();
});
function animate(){
requestAnimationFrame( animate );
/************************************
* Execute the rendering. Returns
* false if VRMode is not enabled
*************************************/
var isSuccessfulRender = g_vr.render();
/******************************************
* Normally you'd have a "normal" perspective camera
* in which case you'll want to add something like this:
*
* if(!isSuccessfulRender){
* g_renderer.render( g_scene, boringMonoCamera );
* }
*******************************************/
}
</script>
</head>
<body>
<button id="start-button" >Start VR</button>
<div class="threejs-container"></div>
</body>
</html>