-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
334 lines (286 loc) · 7.63 KB
/
index.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
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Streetmix - angled parking test</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Rubik" rel="stylesheet" type="text/css">
<style>
html, body {
width: 100%;
height: 100%;
}
body {
margin: 0;
overflow: hidden;
background-color: #a9ccdb;
}
#howto {
box-sizing: border-box;
position: absolute;
left: 0;
width: 100%;
bottom: 0;
text-align: center;
padding: 4em 1em;
pointer-events: none;
font-family: 'Rubik', sans-serif;
color: #404040;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
.loader {
margin: 60px auto;
font-size: 10px;
position: relative;
text-indent: -9999em;
border-top: 1.1em solid rgba(255, 255, 255, 0.2);
border-right: 1.1em solid rgba(255, 255, 255, 0.2);
border-bottom: 1.1em solid rgba(255, 255, 255, 0.2);
border-left: 1.1em solid #ffffff;
-webkit-transform: translateZ(0);
-ms-transform: translateZ(0);
transform: translateZ(0);
-webkit-animation: load8 1.1s infinite linear;
animation: load8 1.1s infinite linear;
}
.loader,
.loader:after {
border-radius: 50%;
width: 10em;
height: 10em;
}
@-webkit-keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
@keyframes load8 {
0% {
-webkit-transform: rotate(0deg);
transform: rotate(0deg);
}
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
}
#loader {
position: absolute;
left: 50%;
bottom: 50%;
margin-bottom: 10px;
margin-left: -20px;
width: 40px;
height: 40px;
border-width: 4px;
box-sizing: border-box;
}
#view {
cursor: ew-resize;
}
#controls {
margin-top: 10px;
}
input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: #f1f7f9;
border: 0;
border-radius: 4px;
resize: none;
padding: 0.5em;
pointer-events: auto;
margin-right: 0.5em;
}
button {
outline: none;
border: 0;
border-radius: 4px;
background-color: #ddf3f9;
padding: 0.5em 1em;
color: #336c71;
font-weight: bold;
text-align: center;
text-decoration: none;
cursor: pointer;
pointer-events: auto;
}
#angle {
width: 40px;
}
</style>
</head>
<body>
<div id="view"></div>
<div id="loader" class="loader"></div>
<div id="howto">
Drag left or right
<div id="controls">
<input id="angle" type="text">
<button id="screenshot">save image</button>
</div>
</div>
<script src="js/three.min.js"></script>
<script src="js/DRACOLoader.js"></script>
<script src="js/ColladaLoader.js"></script>
<script src="js/GLTFLoader.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/hand.min.1.3.8.js"></script>
<script src="js/FileSaver.min.js"></script>
<script>
'use strict'
var scene
var camera
var renderer
var controls
var animation
var angleInput = document.getElementById('angle')
var Z_CLIPPING_PLANE = 300
var MODEL_SCALE = 50
function init () {
scene = new THREE.Scene()
var container = document.getElementById('view')
var HEIGHT = window.innerHeight
var WIDTH = window.innerWidth
var fieldOfView = 60
var nearPlane = 1
var farPlane = 2000
camera = new THREE.OrthographicCamera(
WIDTH / -2,
WIDTH / 2,
HEIGHT / 2,
HEIGHT / -2,
nearPlane,
farPlane
)
camera.position.x = 0 // Straight on view to start
camera.position.y = 0
camera.position.z = Z_CLIPPING_PLANE
camera.lookAt(new THREE.Vector3(0, 0, 0))
renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true,
preserveDrawingBuffer: true
})
renderer.setPixelRatio(window.devicePixelRatio || 1)
renderer.setSize(WIDTH, HEIGHT)
container.appendChild(renderer.domElement)
document.addEventListener('pointerdown', onPointerDown, false)
document.addEventListener('pointerup', onPointerUp, false)
window.addEventListener('resize', onWindowResize, false)
angleInput.addEventListener('change', onAngleInputChange, false)
document.getElementById('screenshot').addEventListener('click', onClickSaveImage, false)
}
function onWindowResize () {
var HEIGHT = window.innerHeight
var WIDTH = window.innerWidth
camera.left = WIDTH / -2
camera.right = WIDTH / 2
camera.top = HEIGHT / 2
camera.bottom = HEIGHT / -2
camera.updateProjectionMatrix()
renderer.setSize(WIDTH, HEIGHT)
render()
}
function onPointerDown () {
loop()
}
function onPointerUp () {
endloop()
}
function onAngleInputChange (event) {
var input = Number(event.target.value)
setCameraToAngle(input)
}
function onClickSaveImage (event) {
event.preventDefault()
saveScreenshot()
}
function addOrbitControls () {
// Orbit controls
controls = new THREE.OrbitControls(camera, renderer.domElement)
controls.enableZoom = false
controls.enablePan = false
controls.rotateSpeed = 1.8
// Lock to horizontal view
controls.minPolarAngle = Math.PI / 2
controls.maxPolarAngle = Math.PI / 2
}
function addLights () {
var light = new THREE.HemisphereLight(0xffffff, 0xffffff, 1)
scene.add(light)
}
function addCar () {
// var loader = new THREE.ColladaLoader()
// loader.load('data/car2.dae', function (result) {
// var collada = result.scene
// collada.scale.x = collada.scale.y = collada.scale.z = 100
// collada.updateMatrix()
// scene.add(collada)
// document.getElementById('loader').style.display = 'none'
// render()
// })
var loader = new THREE.GLTFLoader()
var dracoLoader = new THREE.DRACOLoader()
dracoLoader.setDecoderPath('./js/lib/draco/')
loader.setDRACOLoader(dracoLoader)
loader.load('data/car.glb', function (gltf) {
var model = gltf.scene
model.scale.x = model.scale.y = model.scale.z = MODEL_SCALE
model.updateMatrix()
scene.add(model)
document.getElementById('loader').style.display = 'none'
render()
}, undefined, function (error) {
console.error(error)
})
}
function loop () {
render()
animation = window.requestAnimationFrame(loop)
}
function endloop () {
render()
window.cancelAnimationFrame(animation)
}
function render () {
if (controls) {
controls.update()
// Display the angle
angleInput.value = Math.round(getAngle())
}
renderer.render(scene, camera)
}
function getAngle() {
return controls.getAzimuthalAngle() * (180 / Math.PI)
}
function setCameraToAngle (angle) {
var theta = angle * Math.PI / 180
var x = Z_CLIPPING_PLANE * Math.sin(theta)
var z = Z_CLIPPING_PLANE * Math.cos(theta)
controls.object.position.x = x
controls.object.position.z = z
render()
}
function saveScreenshot () {
var data = renderer.domElement.toBlob(function (blob) {
saveAs(blob, 'angled-parking-@' + Math.round(getAngle()) + '-degrees.png')
})
}
init()
addCar()
addLights()
addOrbitControls()
render()
</script>
</body>
</html>