-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.html
228 lines (188 loc) · 7.52 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
<!--
Copyright 2021 Google LLC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!DOCTYPE html>
<html>
<head>
<title>Stereo image web component</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/svg+xml" href="icon.svg">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:creator" content="@steren">
<meta name="twitter:title" content="Stereo image web component">
<meta name="twitter:image" content="https://stereo-img.steren.fr/title.png">
<meta property="og:type" content="article">
<meta property="og:title" content="Stereo image web component">
<meta property="og:image" content="https://stereo-img.steren.fr/title.png">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"author": "Steren Giannini",
"name": "Stereo image web component",
"image": "https://stereo-img.steren.fr/title.png"
}
</script>
<!-- Polyfill for WebXR -->
<script src='https://cdn.jsdelivr.net/npm/webxr-polyfill@latest/build/webxr-polyfill.js'></script>
<script>
window.polyfill = new WebXRPolyfill();
</script>
<script type="module" src="./stereo-img.js"></script>
<style>
html {
max-width: 70ch;
padding: 3em 1em;
margin: auto;
line-height: 1.75;
font-size: 1.25em;
font-family: sans-serif;
}
h1,h2,h3,h4,h5,h6 {
margin: 3em 0 1em;
}
p,ul,ol {
margin-bottom: 2em;
}
img, stereo-img {
width: 100%;
height: 400px;
}
.icon {
float: left;
margin-right: 1em;
width: 3em;
height: 3em;
}
pre {
overflow-x:auto;
font-size:0.8em;
}
</style>
</head>
<body id='dropbox'>
<header>
<img src="icon.svg" alt="icon" class="icon">
<h1><stereo-img></h1>
<p>
A web component for stereo 3D pictures with VR support (<a href="https://github.com/steren/stereo-img">GitHub</a>).<br>
It supports VR Photos (VR180, Google Camera panorama, Cardboard camera), left-right, and anaglyph.<br>
</p>
</header>
<main>
<h2>Demo</h2>
<p>
<label for="input">Drag and drop or select your stereo pictures:</label>
<input type="file" id="input" multiple accept="image/*">
</p>
<p>
<label for="examples">Or try these:</label>
<select id="examples">
<option value='{"src": "examples/vr180-lenovo-mirage.vr.jpg", "type": "vr"}'> Lenovo Mirage VR180</option>
<option value='{"src": "examples/pixel3xl.PANO.jpg", "type": "vr"}'> Google Camera Panorama</option>
<option value='{"src": "examples/walrus-360.top-bottom.jpg", "type": "top-bottom", "angle": 360}'>Google Camera panorama (top-bottom)</option>
<option value='{"src": "examples/kandao-qoocam-ego.jpg"}'> Kandao QooCam EGO 3D Camera (left-right)</option>
<option value='{"src": "examples/GOPR0.left-right.jpg", "type": "left-right"}'> Go Pro hand made (left-right)</option>
<option value='{"src": "examples/canon-eos-r5-dual-fisheye.jpg"}'> Canon EOS RF5.2mm F2.8 Dual fisheye</option>
<option value='{"src": "examples/calf-vr180.jpg", "angle": 180}'> CALF VR180</option>
<option value='{"src": "examples/calf-left-right.jpg"}'> CALF (left-right)</option>
<option value='{"src": "examples/insta360evo.jpg"}'> Insta360 Evo</option>
<option value='{"src": "examples/stereograph.left-right.jpg", "type": "left-right"}'> Stereograph from 1901</option>
<option value='{"src": "examples/wikipedia.anaglyph.jpg", "type": "anaglyph"}'> Anaglyph</option>
</select>
</p>
<stereo-img src="examples/vr180-lenovo-mirage.vr.jpg" type="vr"></stereo-img>
<button id="previous">Previous</button> <button id="next">Next</button> (or use left/right keyboard keys)
<p>These are best viewed in VR, click "Enter VR" if your device supports VR.</p>
<h2>Use it</h2>
<p>To add this viewer to your page or app:
<pre><code>
<script type="module" src="https://stereo-img.steren.fr/stereo-img.js"></script>
<stereo-img src="picture.vr.jpg"></stereo-img>
</code></pre>
</p>
<h2>For info</h2>
<p>Just for comparison, here is the same picture in a regular <code><img></code> element:</p>
<img src="examples/vr180-lenovo-mirage.vr.jpg" id="img-ref">
</main>
<script>
// On dropdown item selection, update <stereo-img>
const examples = document.getElementById('examples');
examples.addEventListener('change', (e) => {
const { src, type, angle } = JSON.parse(e.target.value);
const stereoImg = document.querySelector('stereo-img');
stereoImg.src = src;
stereoImg.type = type;
stereoImg.angle = angle;
const img = document.getElementById('img-ref');
img.src = src;
});
function previous() {
const index = examples.selectedIndex;
if (index > 0) {
examples.selectedIndex = index - 1;
examples.dispatchEvent(new Event('change'));
}
}
function next() {
const index = examples.selectedIndex;
if (index < examples.options.length - 1) {
examples.selectedIndex = index + 1;
examples.dispatchEvent(new Event('change'));
}
}
document.getElementById('previous').addEventListener('click', previous);
document.getElementById('next').addEventListener('click', next);
// listen for arrow keypress and go to previous / next option in dropdown examples
document.addEventListener('keydown', (e) => {
if (e.keyCode == 37 || e.keyCode === 38) {
previous();
} else if (e.keyCode == 39 || e.keyCode === 40) {
next();
}
});
// Add selected files to dropdown
function handleFiles(files) {
for (let i = 0; i < files.length; i++) {
let file = files[i];
if (!file.type.startsWith('image/')){ continue }
let reader = new FileReader();
reader.onload = e => { processFile(e.target.result, file.name); };
reader.readAsDataURL(file);
}
}
// Add a URL to the dropdown
function processFile(url, name) {
const newOption = document.createElement("option");
newOption.value = JSON.stringify({ src: url });
newOption.text = name;
examples.appendChild(newOption);
examples.selectedIndex = examples.options.length - 1;
examples.dispatchEvent(new Event('change'));
}
document.getElementById("input").addEventListener("change", (e) => {
handleFiles(e.target.files);
}, false);
// Drag and drop
const dropzone = document.getElementById("dropbox");
dropzone.ondragover = dropzone.ondragenter = (e) => {
e.stopPropagation();
e.preventDefault();
}
dropzone.ondrop = (e) => {
e.stopPropagation();
e.preventDefault();
handleFiles(e.dataTransfer.files);
}
</script>
</body>
</html>