-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
238 lines (177 loc) · 6.06 KB
/
index.html
File metadata and controls
238 lines (177 loc) · 6.06 KB
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js webgl - loaders - OBJ loader</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<style>
body {
font-family: Monospace;
background-color: #000;
color: #fff;
margin: 0px;
overflow: hidden;
}
#info {
color: #fff;
position: absolute;
top: 10px;
width: 100%;
text-align: center;
z-index: 100;
display:block;
}
#info a, .button { color: #f00; font-weight: bold; text-decoration: underline; cursor: pointer }
</style>
</head>
<body>
<div id="info">
<a href="http://threejs.org" target="_blank">three.js</a> - OBJLoader test
</div>
<script src="js/three.js"></script>
<script src="js/OBJLoader.js"></script>
<!--
VRControls.js acquires positional information from connected VR devices and applies the transformations to a three.js camera object.
-->
<script src="js/VRControls.js"></script>
<!--
VREffect.js handles stereo camera setup and rendering.
-->
<script src="js/VREffect.js"></script>
<!--
A polyfill for WebVR using the Device{Motion,Orientation}Event API.
-->
<script src="js/webvr-polyfill.js"></script>
<!--
Helps enter and exit VR mode, provides best practices while in VR.
-->
<script src="js/webvr-manager.js"></script>
<script>
var container;
var camera, scene, renderer;
var controls, effect, manager;
var mouseX = 0, mouseY = 0;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;
var clock = new THREE.Clock();
init();
animate();
function init() {
container = document.createElement( 'div' );
document.body.appendChild( container );
camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = -100;
// scene
scene = new THREE.Scene();
var lighting = new THREE.Object3D();
scene.add(lighting);
var root = new THREE.Object3D();
scene.add(root);
var keyLight = new THREE.DirectionalLight();
keyLight.position.set(60, 80, 50);
keyLight.intensity = 0.95;
lighting.add(keyLight);
var backLight = new THREE.DirectionalLight();
backLight.position.set(-250, 50, -200);
backLight.intensity = 0.4;
lighting.add(backLight);
var fillLight = new THREE.DirectionalLight();
fillLight.position.set(-500, -500, 0);
fillLight.intensity = 0.7;
lighting.add(fillLight);
var edgesScene = new THREE.Scene();
var edgesRoot = new THREE.Object3D();
edgesScene.add(edgesRoot);
// texture
var loadManager = new THREE.LoadingManager();
loadManager.onProgress = function ( item, loaded, total ) {
console.log( item, loaded, total );
};
var texture = new THREE.Texture();
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
}
};
var onError = function (xhr) {
console.log("error", arguments);
};
var loader = new THREE.ImageLoader( loadManager );
loader.load( 'assets/UV_Grid_Sm.jpg', function ( image ) {
texture.image = image;
texture.needsUpdate = true;
} );
// model
var loader = new THREE.OBJLoader( loadManager );
loader.load('assets/model.obj', function (object) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material.map = texture;
}
});
object.position.y = -100;
scene.add(object);
}, onProgress, onError );
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(window.innerWidth, window.innerHeight);
// Apply VR headset positional data to camera.
controls = configControls_three(camera);
// Apply VR stereo rendering to renderer.
effect = configEffect_three(renderer);
// Create a VR manager helper to enter and exit VR mode.
manager = new WebVRManager(renderer, effect, { hideButton: false });
manager.button.on("click", function () {
console.log("Change modes");
});
container.appendChild( renderer.domElement );
window.addEventListener('keydown', onKey, true);
var resize = resize_three;
window.addEventListener('resize', resize, false);
setTimeout(resize, 1);
}
function configControls_three(camera) {
return new THREE.VRControls(camera);
}
function configEffect_three(renderer) {
var effect = new THREE.VREffect(renderer);
effect.setSize(window.innerWidth, window.innerHeight);
return effect;
}
function resize_three() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
render_card();
}
function render_card() {
var dt = clock.getDelta();
resize();
camera.updateProjectionMatrix();
controls.update(dt);
// render
// effect.render(scene, camera);
manager.render( scene, camera );
}
function resize() {
var width = container.offsetWidth;
var height = container.offsetHeight;
camera.aspect = width / height;
camera.updateProjectionMatrix();
renderer.setSize(width, height, false);
}
// Reset the position sensor when 'z' pressed.
function onKey(event) {
if (event.keyCode == 90) { // z
controls.resetSensor();
}
};
</script>
</body>
</html>