-
Notifications
You must be signed in to change notification settings - Fork 0
/
tunnel.html
157 lines (122 loc) · 3.95 KB
/
tunnel.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE html>
<html lang="en">
<head>
<title>Shiny Tunnel</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<meta name="mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<style>
body {
background-color: #000;
color: #fff;
margin: 0px;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
</body>
<script src="js/three.min.js"></script>
<script src="js/VRControls.js"></script>
<script src="js/VREffect.js"></script>
<script src="js/webvr-polyfill.js"></script>
<script src="js/webvr-manager.js"></script>
<script src="js/manifold.js"></script>
<script>
var M = manifold;
var renderer = new THREE.WebGLRenderer({ antialias: true });
document.body.appendChild(renderer.domElement);
// Create a three.js scene
var scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x000000, 10, 25 );
var light = new THREE.PointLight( 0xffffff, 1, 0 );
light.position.set( 0,0,0 );
scene.add( light );
light = new THREE.PointLight( 0x33302c, 1, 0 );
light.position.set( 0,.8, -5);
scene.add( light );
light = new THREE.PointLight( 0x33302c, 1, 0 );
light.position.set( 0,.8, 5);
scene.add( light );
// Create a three.js camera
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, .1, 100000);
// Apply VR headset positional data to camera.
var controls = new THREE.VRControls(camera);
// Apply VR stereo rendering to renderer
var effect = new THREE.VREffect(renderer);
effect.setSize(window.innerWidth, window.innerHeight);
// Create a VR manager helper to enter and exit VR mode.
var vrmgr = new WebVRManager(effect);
// Create 3d objects
var threeGeometry = M.ThreeJSRenderer();
var geometry = threeGeometry.geometry;
function randomize(theta, z) {
var variance = .4;
var width = .75;
var x = width*Math.cos(theta) + Math.random()*variance - .2;
var y = width*Math.sin(theta) + Math.random()*variance;
var z = z + Math.random() * variance;
return [x,y,z];
}
var spine = M.Path([0,0,-400]).line([0,0,0]);
var N = 13;
M.PathParameterized(spine, 1000, N+1)
( function(profile) {
var origin = randomize(0,profile.z);
var path = M.Path(origin);
for (var i=1; i<N; i++)
path = path.line(randomize(2*Math.PI*i/N, profile.z));
path = path.line(origin);
return path;
}
)
( M.facers( M.skin )
( threeGeometry.renderer )
);
//geometry.computeBoundingSphere();
geometry.computeFaceNormals();
//var geometry = new THREE.IcosahedronGeometry(10, 1); // new THREE.BoxGeometry(10, 10, 10);
var tunnel = THREE.SceneUtils.createMultiMaterialObject(
geometry.clone(), [
new THREE.MeshPhongMaterial({ color: 0x00000, shininess:80, specular: 0xaa9999 }),
new THREE.MeshBasicMaterial({ wireframe: true, wireframeLinewidth:2, color: 0xefe9e6 })
]);
// Position tunnel mesh
tunnel.position.z = -25;
// Add tunnel mesh to your three.js scene
scene.add(tunnel);
// Request animation frame loop function
function animate() {
// Apply rotation to tunnel mesh
tunnel.position.z += 0.05;
// Update VR headset position and apply to camera.
controls.update();
// Render the scene through the VREffect, but only if it's in VR mode.
if (vrmgr.isVRMode()) {
effect.render(scene, camera);
} else {
renderer.render(scene, camera);
}
requestAnimationFrame( animate );
}
// Kick off animation loop
animate();
// Listen for keyboard event and zero positional sensor on appropriate keypress.
function onKey(event) {
if (event.keyCode == 90) { // z
controls.zeroSensor();
}
};
window.addEventListener('keydown', onKey, true);
// Handle window resizes
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
effect.setSize( window.innerWidth, window.innerHeight );
}
window.addEventListener('resize', onWindowResize, false);
</script>
</html>